package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.serviceutil.service.OssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/8/27 23:24
 */
@Slf4j
@RestController
@RequestMapping("/admin/product")
public class FileController {
    @Autowired
    private OssService ossService;

    //文件上传接口
    //MultipartFile 是一个接口，代表一个文件，可以上传到服务器上
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file) throws Exception {
        log.info("文件名:{},文件大小:{},文件类型:{}", file.getOriginalFilename(), file.getSize(), file.getContentType());
        String url = ossService.fileUpload(file);
        return Result.ok(url);
    }
}
